package com.wopinla.service.impl;
import com.wopinla.pojo.*;
import com.wopinla.dao.ExampleDao;
import com.wopinla.pojo.Example;
import com.wopinla.service.ExampleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service   //添加注解
public class ExampleServiceImpl implements ExampleService {

    //注入dao层（调用dao）
    @Autowired
    private ExampleDao exampleDao;   //红线不要紧

    @Override
    public List<Example> getExampleByMap(Map<String, Object> map) {
        /*
        * service层，服务层，相对比dao层更高级的一层，可以把更多其他操作封装再次层，
        */
        return exampleDao.getExampleByMap(map);


    }
    @Override
    public int addUser(Map<String, Object> map)
    {
        return  exampleDao.addUser(map);
    }
    @Override
    public int deleteUser(Map<String, Object> map)
    {
        return  exampleDao.deleteUser(map);
    }
    @Override
    public int login(Map<String,Object> map)
    {
        user user;
        System.out.println("Service层");
        user= exampleDao.getUserById((Integer)map.get("id"));
        System.out.println("查找完成");
        if(user.getPassword().equals(map.get("password"))&&user.getIdentity().equals(map.get("identity")))
        {
            System.out.println("密码正确");
            Integer aaa=exampleDao.deregulation((Integer)map.get("id"));
            if(aaa!=null)
            {
                System.out.println("账号被封禁");
                return 2;
            }
            return 1;
        }
        else
        {
            System.out.println("密码错误");
            return 0;
        }
    }
    @Override
    public int updateUser(Map<String,Object>  map)
    {
        return exampleDao.updateUser(map);
    }
    @Override
    public List<user> userroot(Integer id){return exampleDao.userroot(id);}
    @Override
    public user userById(Integer id)
    {
        System.out.println("userById");
        return exampleDao.userById(id);
    }
    @Override
    public List<user> unuser(){return exampleDao.unuser();}



}
